﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotNetNuke.Modules.DNNFiddle.Components
{
    public static class UriExtensions
    {
        public static string ToAbsolutePath(this string path)
        {
            Uri uri = new Uri(path, UriKind.RelativeOrAbsolute);

            //If the URI is not already absolute, rebuild it based on the current request.
            if (!uri.IsAbsoluteUri)
            {
                UriBuilder builder = new UriBuilder(HttpContext.Current.Request.Url);

                //All that needs to change is the path portion.
                builder.Path = VirtualPathUtility.ToAbsolute(path);

                uri = builder.Uri;
            }

            return uri.AbsoluteUri.Replace(uri.Query, string.Empty );
        }
    }
}